import logging
import random

import requests

import openapi.account_api as account_api
import openapi.setting as setting


def getFollows(house_id):
    """根据房源id获取房源跟进记录

    Args:
        house_id (_type_): _description_

    Returns:
        _type_: _description_
    """
    url = f'http://erp.fangline.cn/house/get-recently-house-log.json?houseId={house_id}'
    response = requests.post(url, headers=account_api.getDefaultHeaders())
    
    return response.json()['followLogs']


def pushFollow(token, user, house_id):
    """提交跟进记录

    Args:
        token (string): 登录token
        user (string): 账号
        house_id (string): 房源id
    """
    content = random.choice(setting.executorParams["flowerText"])

    url = f'http://erp.fangline.cn/house/writeFollowUp?houseId={house_id}&content={content}&token={token}&imgs=&deleteTag=true'
    response = requests.post(url, headers=account_api.getHeaders(user))
    logging.info(f'房源：{house_id} 子账号填写跟进记录:{content},{response.content}')
